package org.loong.crypto.service.software.provider.random;

import org.loong.crypto.common.exception.CryptoException;
import org.loong.crypto.common.utils.SecureRandomHolder;
import org.loong.crypto.service.core.provider.RandomGenerator;

/**
 * Generic random generator.
 */
public class GenericRandomGenerator implements RandomGenerator {

    @Override
    public byte[] generateRandom(int randomLength) throws CryptoException {
        if (randomLength < 0) {
            throw new CryptoException("The random length is illegal.");
        }

        final byte[] random = new byte[randomLength];
        SecureRandomHolder.getRandom().nextBytes(random);
        return random;
    }
}
